package com.zryc.shop.sms.controller;

import com.zryc.shop.base.Result;
import com.zryc.shop.sms.entity.FlashPromotionProductRelation;
import com.zryc.shop.sms.service.IFlashPromotionProductRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 商品限时购与商品关系表 前端控制器
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@RestController
@Api(tags = "商品限时购与商品关系接口列表")
@RequestMapping("/sms/flashProductRelation")
public class FlashPromotionProductRelationController {

    @Autowired
    private IFlashPromotionProductRelationService flashPromotionProductRelationService;

    @GetMapping("/list")
    @ApiOperation("分页列表")
    public Result list(@RequestParam(defaultValue = "1") @ApiParam(value = "页码", required = true) Integer pageNum,
                       @RequestParam(defaultValue = "5") @ApiParam(value = "每页显示条数", required = true) Integer pageSize,
                       @RequestParam @ApiParam(value = "秒杀活动ID", required = true) Long flashPromotionId,
                       @RequestParam @ApiParam(value = "秒杀时间段ID", required = true) Long flashPromotionSessionId){
        return Result.ok(flashPromotionProductRelationService.list(pageNum,pageSize,flashPromotionId,flashPromotionSessionId));
    }

    @PostMapping("/create")
    @ApiOperation("添加秒杀商品")
    public Result create(@RequestBody List<FlashPromotionProductRelation> relationList){
        return Result.ok(flashPromotionProductRelationService.saveBatch(relationList));
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("删除秒杀商品")
    public Result delete(@PathVariable @ApiParam(value = "限时购-商品关系ID", required = true) Long id){
        return Result.ok(flashPromotionProductRelationService.removeById(id));
    }

    @PostMapping("/update/{id}")
    @ApiOperation("修改秒杀商品信息")
    public Result update(@PathVariable @ApiParam(value = "限时购-商品关系ID", required = true) Long id,
                                 @RequestBody FlashPromotionProductRelation relation){
        return Result.ok(flashPromotionProductRelationService.updateProduct(id,relation));
    }


}
